package com.carkeeper.mongo.listener;

import com.alibaba.fastjson.JSON;
import com.carkeeper.appraise.pojo.Appraisal;
import com.carkeeper.mongo.config.RabbitMQConfig;
import com.carkeeper.mongo.service.MongoService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AdListener {

    @Autowired
    private MongoService mongoService;

    @RabbitListener(queues = RabbitMQConfig.AD_APPRAISAL_QUEUE)
    public void getMessage(String message){
        System.out.println("收到添加消息");
        try {
            mongoService.add(JSON.parseObject(message, Appraisal.class));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
